package user

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"net/http"
)

// binding from JSON
type Login struct {
	Username string `form:"username" json:"username" binding:"required"`
	Password string `form:"password" json:"password" binding:"required"`
}

func login(c *gin.Context) {
	var login Login
	if err := c.ShouldBind(&login); err == nil {
		fmt.Printf("%#v\n", login)
		c.JSON(http.StatusOK, gin.H{
			"user":     login.Username,
			"password": login.Password,
		})
	} else {
		c.JSON(http.StatusBadRequest, gin.H{
			"error": err.Error(),
		})
	}
}
